package com.glamour.hlcity.biz;


import org.springframework.beans.factory.FactoryBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.glamour.hlcity.component.framework.registry.impl.ApplicationContextFactory;

public class BeanContextFactoryBean implements FactoryBean {

    
    /**
     * Bean配置文件路径
     */
    private String[] configLocations;

    public void setConfigLocations(String[] configLocations) {
        this.configLocations = configLocations;
    }

    /**
     * 默认ApplicationContext实例
     */
    private  ApplicationContext context;

    @Override
    public synchronized Object getObject() throws Exception {
        if (context == null) {
            ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(configLocations);
           // ctx.setConfigLocations(configLocations);
            ctx.refresh();
            ApplicationContextFactory.putApplicationContext(ctx);
            context = ctx;        
        }
        return context;
    }
    


    @Override
    public Class getObjectType() {
        return ApplicationContext.class;
    }

    @Override
    public boolean isSingleton() {
        return true;
    }


}
